package com.example.gestioncontacts;

import com.example.BD.ContactsDBAdaptateur;
import com.example.BD.MaBD;
import com.example.metier.Contact;

import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AjoutContact extends Activity {

	private Button bAjouter;
	private Button bAnnuler;
	private EditText eNom;
	private EditText ePrenom;
	private EditText eNum;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ajouter_contact);

		bAjouter = (Button) findViewById(R.id.ajouter);
		bAnnuler = (Button) findViewById(R.id.annuler);
		eNom = (EditText) findViewById(R.id.edNom);
		ePrenom = (EditText) findViewById(R.id.edPrenom);
		eNum = (EditText) findViewById(R.id.edNum);

		bAjouter.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Contact c = new Contact(eNom.getText().toString(), ePrenom
						.getText().toString(), eNum.getText().toString());

					
				ContactsDBAdaptateur cda = new ContactsDBAdaptateur(AjoutContact.this);
				cda.open();
				cda.insertContact(c);
				cda.close();
						
				Toast.makeText(AjoutContact.this, c + " a ete Ajoute",
						Toast.LENGTH_LONG).show();
				
				Intent i = new Intent(AjoutContact.this, MainActivity.class);
				startActivity(i);
				

			}
		});

		bAnnuler.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent i = new Intent(AjoutContact.this, MainActivity.class);
				startActivity(i);

			}
		});
	}
}
